<template>
  <div>
    <van-nav-bar title="详情" left-arrow v-back left-text="返回" fixed />
    <div class="order-detail__container">
      <div class="order-detail">
        <div class="order-detail__title">
          <div class="order-detail__title__tag"></div>
          <div class="order-detail__title__text">订单信息</div>
        </div>
        <div class="order-detail__content">
          <div class="order-detail__item">
            <div class="order-detail__item__tit">订单号：</div>
            <div class="order-detail__item__content">{{detail.id}}</div>
          </div>
          <div class="order-detail__item">
            <div class="order-detail__item__tit">下单时间：</div>
            <div class="order-detail__item__content">{{detail.time}}</div>
          </div>
          <div class="order-detail__item">
            <div class="order-detail__item__tit">支付方式：</div>
            <div class="order-detail__item__content">{{detail.paytype == false ? '线上付款' : '线下支付'}}</div>
          </div>
          <div class="order-detail__item">
            <div class="order-detail__item__tit">押桶方式：</div>
            <div class="order-detail__item__content">{{detail.barrel == false ? '押桶' : '购桶'}}</div>
          </div>
          <div class="order-detail__item">
            <div class="order-detail__item__tit">订单总额：</div>
            <div class="order-detail__item__content order-detail__total">{{detail.asum}}元</div>
          </div>
          <div class="order-detail__item">
            <div class="order-detail__item__tit">订单备注：</div>
            <div class="order-detail__item__content">{{detail.remark}}</div>
          </div>
        </div>
      </div>
      <div class="order-detail">
        <div class="order-detail__title">
          <div class="order-detail__title__tag"></div>
          <div class="order-detail__title__text">订单商品</div>
        </div>
        <div class="order-detail__content">
          <div class="order-detail__item order-detail__item_product" v-for="item in waterList">
            <div class="order-detail__el order-detail__img" v-bind:style="{backgroundImage: 'url(' + item.icon + ')'}">
            </div>
            <div class="order-detail__el order-detail__name">{{item.waterName}}</div>
            <div class="order-detail__el order-detail__price">￥{{item.asum}}</div>
            <div class="order-detail__el order-detail__num">x{{item.anum}}</div>
          </div>
        </div>
      </div>
      <div class="order-detail">
        <div class="order-detail__title">
          <div class="order-detail__title__tag"></div>
          <div class="order-detail__title__text">{{getType}}桶记录</div>
        </div>
        <div class="order-detail__content">
          <div class="order-detail__item order-detail__item_product" v-for="item in detailList" v-if="item.num !== 0">
            <!-- <div class="order-detail__el order-detail__img">
            </div> -->
            <div class="order-detail__el order-detail__name">{{item.bucketName}}</div>
            <div class="order-detail__el order-detail__price">￥{{item.num * item.bucketPrice}}</div>
            <div class="order-detail__el order-detail__num">x{{item.num}}</div>
          </div>
          <div class="order-detail__item order-detail__item_total">
            <div class="order-detail__el">总计{{getType}}桶金额：<span>￥{{debtTotal}}</span></div>
          </div>
        </div>
      </div>
      <!-- <div class="order-detail">
        <div class="order-detail__title">
          <div class="order-detail__title__tag"></div>
          <div class="order-detail__title__text">还桶记录</div>
        </div>
        <div class="order-detail__content">
          <div class="order-detail__item order-detail__item_product" v-for="item in 2">
            <div class="order-detail__el order-detail__img">
            </div>
            <div class="order-detail__el order-detail__name">恒大一次性桶装水水桶</div>
            <div class="order-detail__el order-detail__num">x2</div>
          </div>
          <div class="order-detail__item order-detail__item_total">
            <div class="order-detail__el">总计还桶金额：<span>100元</span></div>
          </div>
        </div>
      </div> -->
    </div>
  </div>
</template>
<script>
  import {
    BUCKET_LOSS_DETAIL
  } from '@/api/user'
  import {
    ORDER_DETAIL
  } from '@/api/stock'
  export default {
    data() {
      return {
        detail: {},
        detailList: [], //记录列表
        waterList: [],  //水列表
        type: '', //欠或者买（debt/buy）
      }
    },
    computed: {
      debtTotal(){
        let res = 0;
        this.detailList.forEach(el => {
          res += el.num * el.bucketPrice;
        });
        return res;
      },
      getType(){
        if(this.type == 'debt'){
          return '欠';
        }else if(this.type == 'buy'){
          return '买';
        }else if(this.type == 'repay'){
          return '还';
        }else if(this.type == 'exchange'){
          return '换';
        }
      }
    },
    mounted() {
      this.type = this.$route.query.type;
      this.detail = this.$route.query.item;
      //记录列表
      if(this.type == 'debt'){
        this.detailList = this.detail.bucketDebtList;
      }else if(this.type == 'buy'){
        this.detailList = this.detail.bucketBuyList;
      }else if(this.type == 'repay'){
        this.detailList = this.detail.bucketRepayList;
      }else if(this.type == 'exchange'){
        this.detailList = this.detail.bucketExchangeList;
      }
      // this.getDetail();
      this.getOrderDetail();
    },
    methods: {
      //获取欠桶详情
      getDetail() {
        this.$reqGet(BUCKET_LOSS_DETAIL, {
          orderId: this.$route.query.item.id
        }).then(res => {
          this.detailList = res.rows;
        });
      },
      //获取订单详情
      getOrderDetail(){
        this.$reqGet(ORDER_DETAIL, {
          orderId: this.$route.query.item.id
        }).then(res => {
          this.waterList = res.rows[0].orderWaterList;
        });
      }
    },
  }

</script>
<style lang="less" scoped>
  @import '../../styles/variable.less';

  .order-detail__container {
    position: absolute;
    top: 46px;
    // bottom: 40px;
    width: 100%;
    background-color: #f5f5f5;
    overflow: auto;
  }



  .order-detail {
    border-radius: 5px;
    margin: 8px;
    padding: 10px 10px 5px 10px;
    background-color: #ffffff;
    margin-bottom: 10px;
    color: #666666;
  }

  .order-detail__title {
    position: relative;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #eeeeee;
    padding-bottom: 8px;
    margin-bottom: 8px;

    .order-detail__title__tag {
      flex: 0 0 4px;
      height: 17px;
      margin-top: 2px;
      margin-right: 6px;
      background-color: @col-the;
    }

    .order-detail__title__status {
      position: absolute;
      right: 5px;
      top: 0px;

      &.order-status_cancel {
        color: #999999;
      }

      &.order-status_unpay {
        color: @col-red;
      }

      &.order-status_wait {
        color: @col-yellow;
      }

      &.order-status_sending {
        color: @col-the;
      }
    }

    .order-detail__title__phone {
      position: absolute;
      right: 5px;
      top: 2px;

      i {
        font-size: 18px;
      }
    }
  }

  .order-detail__item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 12px;
    &.order-detail__item_total{
      padding-right: 10px;
      justify-content: flex-end;
      color: @col-the;
    }
    .order-detail__item__tit {
      flex: 0 0 70px;
      color: #999;
    }

    .order-detail__item__content {
      color: #343434;

      &.order-detail__total {
        color: @col-the;
      }

      &.order-detail__item__address {
        text-align: right;
      }
    }

    &.order-detail__item_product {
      align-items: center;
      color: #999999;
    }



    .order-detail__el {
      font-size: 12px;

      &.order-detail__img {
        flex: 0 0 60px;
        height: 60px;
        background-size: contain;
        background-position: center;
        background-repeat: no-repeat;
        background-image: url('../../assets/product.png')
      }

      &.order-detail__name {
        flex: 0 0 35%;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
      }

      &.order-detail__num {
        width: 45px;
        text-overflow: ellipsis;
        overflow: hidden;
        text-align: center;
      }

      &.order-detail__status_sending,
      &.order-detail__total {
        color: @col-the;
      }

      &.order-detail__receiver {
        color: #888;
      }
    }
  }

  .edit-address__btn {
    position: absolute;
    top: 3px;
    right: 5px;
    font-size: 12px;
    color: @col-the;

    i {
      position: relative;
      top: 2px;
    }
  }

  .operate-btn {
    position: fixed;
    bottom: 0;
    width: 100%;
    font-size: 14px;
    letter-spacing: 10px;
  }

</style>
